<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>帐号登陆</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
    
<script src="./layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'jquery'], function(){
        var layer = layui.layer,
        form = layui.form,
        $ = layui.jquery;

        layer.prompt({title: '请输入您的名字', formType: 3, btn: ['登陆或创建帐号'], closeBtn: 0}, function(name, index){
            $.ajax({
                url: '/login',
                type: 'POST',
                dataType: 'json',
                data: {username: name},
            })
            .done(function(e) {
                if (e.code == 200) {
                    layer.close(index);
                    layer.msg(e.msg, {t:2000}, function(){
                        window.location.href = e.url;
                    });
                }else{
                    layer.msg(e.msg);
                }
            })
            .fail(function() {
                layer.msg('请求错误，情刷新重试！');
            })
            .always(function() {
                console.log('正在提交...');
            });
            
        });
    });
</script> 
</body>
</html>